package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVo;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 学生课程表 控制器
 * </p>
 *
 * @author author
 */
@Api(tags = "LearningLesson管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/lessons")
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    /**
     * 课表分页查询
     * @param query
     * @return
     */
    @ApiOperation("课表分页查询")
    @GetMapping("/page")
    public PageDTO<LearningLessonVo> page(PageQuery query) {
        return learningLessonService.pageQuery(query);
    }

    /**
     * 查询正在学习的课程
     * @return
     */
    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVo now() {
        LearningLessonVo learningLessonVo= learningLessonService.now();
        return learningLessonVo ;
    }

    /**
     * 删除课程
     * @param courseId
     */
    @ApiOperation("删除课程")
    @DeleteMapping("{courseId}")
    public void deleteByCourseId(@PathVariable Long courseId) {
        learningLessonService.deleteByCourseId(courseId);
    }

    /**
     * 检查课程是否有效
     * @param courseId 课程id
     * @return lessonId，如果是报名了则返回lessonId，否则返回空
     */
    @ApiOperation("检查课程是否有效")
    @GetMapping("{courseId}/valid")
    public Long isLessonValid(@PathVariable("courseId") Long courseId){
       return learningLessonService.isLessonValid(courseId);
    }
    /**
     * 查询用户课表中指定课程状态
     * @param courseId
     */
    @ApiOperation("查询用户课表中指定课程状态")
    @GetMapping("{courseId}")
    public LearningLessonVo selectByCourseId(@PathVariable Long courseId) {
       return learningLessonService.selectByCourseId(courseId);
    }
    /**
     * 统计课程的学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @ApiOperation("统计课程的学习人数")
    @GetMapping("{courseId}/count")
    public  Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    public void createLearningPlans( @RequestBody LearningPlanDTO planDTO){
        learningLessonService.createLearningPlan(planDTO);
    }
    @ApiOperation("查询学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO selectLearningPlan(PageQuery query){
        return learningLessonService.selectLearningPlan(query);
    }

}
